package entity;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

@Table(name = "scott.emp")
@Entity
public class Emp implements Serializable {
	@Id
	private Integer empNo;
	private String ename;
	private String job;
	private Double mgr;
	private Date hiredate;
	private Double sal;
	private Double comm;
	// private Integer deptNo; //部门编号

	@JoinColumn(name = "DEPTNO")
	@ManyToOne(targetEntity = Dept.class)
	private Dept dept;// 多对一 部门对象

	// 多对多 项目集合
	// @JoinColumn(table = "proemp", name = "EMPNO")
	@JoinTable(name = "proemp", joinColumns = {
			@JoinColumn(name = "EMPNO", referencedColumnName = "empNo") }, 
			inverseJoinColumns = {
					@JoinColumn(name = "PRONO", referencedColumnName = "proNo") })
	@ManyToMany(targetEntity = Project.class)
	private Set<Project> pros = new HashSet<>();

	public Set<Project> getPros() {
		return pros;
	}

	public void setPros(Set<Project> pros) {
		this.pros = pros;
	}

	// 忽略不是表中的列
	@Transient
	private Date startDate;
	@Transient
	private Date endDate;

	public Dept getDept() {
		return dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public Emp() {
	}

	public Emp(String ename, Double sal) {
		super();
		this.ename = ename;
		this.sal = sal;
	}

	@Override
	public String toString() {
		return "Emp [empNo=" + empNo + ", ename=" + ename + ", job=" + job + ", mgr=" + mgr + ", hiredate=" + hiredate
				+ ", sal=" + sal + ", comm=" + comm + "]";
	}

	public Integer getEmpNo() {
		return empNo;
	}

	public void setEmpNo(Integer empNo) {
		this.empNo = empNo;
	}

	public String getEname() {
		return ename;
	}

	public void setEname(String ename) {
		this.ename = ename;
	}

	public String getJob() {
		return job;
	}

	public void setJob(String job) {
		this.job = job;
	}

	public Double getMgr() {
		return mgr;
	}

	public void setMgr(Double mgr) {
		this.mgr = mgr;
	}

	public Date getHiredate() {
		return hiredate;
	}

	public void setHiredate(Date hiredate) {
		this.hiredate = hiredate;
	}

	public Double getSal() {
		return sal;
	}

	public void setSal(Double sal) {
		this.sal = sal;
	}

	public Double getComm() {
		return comm;
	}

	public void setComm(Double comm) {
		this.comm = comm;
	}

}
